// pages/login/login.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:{logo:'',title:'',article1:'',article2:''},
    page:'page_wxtel',
    face:'',
    name:'',
    time:60,
    mobile: '',
    code: '',
    hash:'',
    ok:0,
    isSend: false,
    btnSendText: '获取验证码' //倒计时格式：(60秒)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.load();
  },

  async load(){
    let res=await wx.util.post("login/info",{},false);
    this.setData({
      info:res.data
    })
  },
  argee(){
    this.setData({ok:this.data.ok==1?0:1});
  },
  protocol(e){
    console.log('e',e)
    wx.navigateTo({
      // url:'/pages/articleDetail/articleDetail?id='+this.data.info.article1
      url:'/pages/articleDetail/articleDetail?id='+e.currentTarget.dataset.id
    })
  },
  checkAgree(){
    if(this.data.ok==0){
      wx.util.toast('请勾选我同意服务协议');
      return;
    }
  },
  async getNumber(e){
    console.log(e)
    this.data.mobile='';
    this.data.hash='';
    if(e.detail.errMsg!="getPhoneNumber:ok"){
      wx.util.toast("授权失败");
      return;
    }
    let res=await wx.util.post("login/bywxtel",e.detail,false);
    this.setData({
      mobile:res.data.tel,
      hash:res.data.hash
    })
    this.login();
  },
  
  async login(){
    if(this.data.ok==0){
      wx.util.toast('请勾选我同意服务协议');
      return;
    }
   
    let sub={};
    sub.tel=this.data.mobile;
    sub.code=this.data.code;
    sub.hash=this.data.hash;
    sub.openid=wx.getStorageSync("openid");
    let res=await wx.util.post("login/index",sub,false);
    wx.setStorageSync("is_login",'1');
    wx.setStorageSync("order_tab",-1);
    wx.util.setToken(res.data.token);
    this.back();
  },
  back() {
    wx.navigateBack();
  }
})